package com.security.oauth2.resource.dto;

import java.io.Serializable;
import lombok.Data;

/**
 * @Author: zyn
 * @Description:
 * @Date: Created in 2019-05-22 15:15
 * @Modified By:
 */
@Data
public class ResponseResult<T> implements Serializable {

  private static final long serialVersionUID = 8486468806063544444L;

  /**
   * 状态码
   */
  private Integer state;

  /**
   * 消息
   */
  private String message;

  /**
   * 返回对象
   */
  private T data;

  public ResponseResult() {
    super();
  }

  public ResponseResult(Integer state) {
    super();
    this.state = state;
  }

  public ResponseResult(Integer state, String message) {
    super();
    this.state = state;
    this.message = message;
  }

  public ResponseResult(Integer state, Throwable throwable) {
    super();
    this.state = state;
    this.message = throwable.getMessage();
  }

  public ResponseResult(Integer state, T data) {
    super();
    this.state = state;
    this.data = data;
  }

  public ResponseResult(Integer state, String message, T data) {
    super();
    this.state = state;
    this.message = message;
    this.data = data;
  }

  public Integer getState() {
    return state;
  }

  public void setState(Integer state) {
    this.state = state;
  }

  public String getMessage() {
    return message;
  }

  public void setMessage(String message) {
    this.message = message;
  }

  public T getData() {
    return data;
  }

  public void setData(T data) {
    this.data = data;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((data == null) ? 0 : data.hashCode());
    result = prime * result + ((message == null) ? 0 : message.hashCode());
    result = prime * result + ((state == null) ? 0 : state.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    ResponseResult<?> other = (ResponseResult<?>) obj;
    if (data == null) {
      if (other.data != null) {
        return false;
      }
    } else if (!data.equals(other.data)) {
      return false;
    }
    if (message == null) {
      if (other.message != null) {
        return false;
      }
    } else if (!message.equals(other.message)) {
      return false;
    }
    if (state == null) {
      if (other.state != null) {
        return false;
      }
    } else if (!state.equals(other.state)) {
      return false;
    }
    return true;
  }

  @Override
  public String toString() {
    return "ResponseResult [state=" + state + ", message=" + message + ", data=" + data + "]";
  }
}
